package com.ojoin.trade.t0loan_core.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbT0StatusOfPosTranscationDao;
import com.ojoin.trade.t0loan_core.web.domain.TbT0StatusOfPosTranscation;
import com.ojoin.trade.t0loan_core.web.service.T0StatusOfPosTranscationBaseService;

/**
 * T+0贷款pos机交易记录状态服务实现
 * @author guoting
 *
 */
@Service
public class T0StatusOfPosTranscationBaseServiceImpl extends BaseServiceImpl<TbT0StatusOfPosTranscation> implements
		T0StatusOfPosTranscationBaseService {

	@Autowired
	private TbT0StatusOfPosTranscationDao dao;
	
	/**
	 * 新建九盈T+0贷款记录包含的pos机交易记录状态表记录(T0000013)
	 */
	@Override
	public int insertPosTransStatusInfo(String posTranscantionId)
			throws BusinessException {
		LogUtils.getT0loanLog().info("新建九盈T+0贷款记录包含的pos机交易记录状态表记录. posTranscantionId->" + posTranscantionId);
		
		TbT0StatusOfPosTranscation contrastvo = new TbT0StatusOfPosTranscation();
		
		//contrastvo设值，放款审核时会调用该新增方法，设置其userdbyload为N，真正放款后才更新其为Y
		contrastvo.setPosTranscantionId(posTranscantionId);
		contrastvo.setUsedByLoan("N");
		contrastvo.setReturnedAfterLoad("N");
		
		this.getBaseDao().insert(contrastvo);
		return contrastvo.getId(); 
	}

	/**
	 * 更新九盈T+0贷款记录包含的pos机交易记录状态表记录的还款状态(T0000014)
	 */
	@Override
	public int updatePosTransStatusInfoReturnStatus(Integer joinuserid, String transdate) throws BusinessException {
		LogUtils.getT0loanLog().info("更新九盈T+0贷款记录包含的pos机交易记录状态表记录的还款状态. joinuserid->" + joinuserid + " transdate->" + transdate );
		
		return ((TbT0StatusOfPosTranscationDao) this
					.getBaseDao()).updatePosTransStatusInfoReturnStatus(joinuserid, transdate);
	}

	
	/**
	 * 更新九盈T+0贷款记录包含的pos机交易记录状态表记录的放款状态
	 */
	@Override
	public int updatePosTransStatusInfoUsedByLoanStatus(Integer joinuserid, String transdate) throws BusinessException {
		LogUtils.getT0loanLog().info("更新九盈T+0贷款记录包含的pos机交易记录状态表记录的放款状态. joinuserid->" + joinuserid + " transdate->" + transdate);
		
		return ((TbT0StatusOfPosTranscationDao) this
					.getBaseDao()).updatePosTransStatusInfoUsedByLoanStatus(joinuserid, transdate);
	}
	
	@Override
	protected BaseDao<TbT0StatusOfPosTranscation> getBaseDao() {
		return dao;
	}

	@Override
	public void insertIntoPosTransStatusInfo(Integer joinuserid, String transdate) throws BusinessException {
		((TbT0StatusOfPosTranscationDao) this
				.getBaseDao()).insertIntoPosTransStatusInfo(joinuserid, transdate);
	}

}
